Repository navigation
Pu/issue709 - #710
Pu/issue709#710
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #710 +/- ##
==========================================
Coverage 92.27% 92.27%
==========================================
Files 166 166
Lines 39412 39412
Branches 5365 3575 -1790
==========================================
Hits 36368 36368
- Misses 3005 3038 +33
+ Partials 39 6 -33
|
| let cnt = 20 | ||
| Date.now = () => { | ||
| cnt += 1 | ||
| return Date.parse(`1985-08-16T03:45:${cnt}`) | ||
| } |
There was a problem hiding this comment.
A more elegant way will be and it's clear its a mock:
| let cnt = 20 | |
| Date.now = () => { | |
| cnt += 1 | |
| return Date.parse(`1985-08-16T03:45:${cnt}`) | |
| } | |
| dateMock = jest.fn().mockReturnValue(new Date('1985-08-16T03:45:30Z').getTime()) | |
| Date.now = dateMock |
I will get to NOW in the next comment
There was a problem hiding this comment.
will it work for the multitude of testers that we have? (jest, jasmine, karma)?
There was a problem hiding this comment.
true, it will not, I forgot about jasmine
There was a problem hiding this comment.
I don't think we should fight for some hybrid jest/jasmine mock tests and just go with what we have. But of course it is up to you
| expect(t1).toBeCloseTo(31275.1565856481) | ||
| expect(engine.getCellValueDetailedType(adr('A1'))).toBe(CellValueDetailedType.NUMBER_DATETIME) | ||
| sleepFor(1000) | ||
| engine.setCellContents(adr('A2'), null) | ||
| const t2 = engine.getCellValue(adr('A1')) as number | ||
| const delta = (t2-t1)*(24*60*60) | ||
| expect(delta).toBeCloseTo(1) | ||
| const delta = engine.getCellValue(adr('A1')) as number - t1 | ||
| expect(delta*24*60*60).toBeGreaterThanOrEqual(1) //internals of the engine are also using Date.now(), so the value should be actually 4 or even more |
There was a problem hiding this comment.
Wouldn't it be better to have this test predictable?
dateMock.mockReturnValueOnce(new Date('1985-08-16T03:45:30Z').getTime())
const t1 = engine.getCellValue(adr('A1'))
dateMock.mockReturnValueOnce(new Date('1985-08-16T03:45:30Z').getTime())
engine.setCellContents(adr('A2'), null)
const t2 = engine.getCellValue(adr('A1'))we will know exactly what time each NOW() returns and can make precise expectation
wojciechczerniak
left a comment
There was a problem hiding this comment.
As @izulin noticed correctly we can't use Jest mocks, they will fail in Jasmine
Context
Fixes #709
How has this been tested?
Types of changes
Related issue(s):
Checklist: